//
// SoundData subclass to load mp3 files
//

#ifndef	__FLAC_SOUND_DATA__
#define	__FLAC_SOUND_DATA__
//Based on XMMS2-flac plugin
//UNDER DEVELOPMENT
#include "SoundData.h"
#include "FLAC/all.h"
#include <glib-2.0/glib.h>

typedef struct {
    FLAC__bool abort_flag;
    FLAC__bool is_playing;
    FLAC__bool is_http_source;
    FLAC__bool eof;
    FLAC__bool play_thread_open; /* if true, is_playing must also be true */
    FLAC__uint64 total_samples;
    unsigned bits_per_sample;
    unsigned channels;
    unsigned sample_rate;
    FLAC__uint64 length_in_msec;
    gchar *title;
    AFormat sample_format;
    unsigned sample_format_bytes_per_sample;
    int seek_to_in_sec;
    FLAC__bool has_replaygain;
    double replay_scale;
    DitherContext dither_context;
} stream_data_struct;


class	FLACSoundData : public SoundData
{
    enum
    {
        BUFFER_SIZE = 4096
    };

    int			fileSize;
    byte		buffer [BUFFER_SIZE];
    byte		outBuf [BUFFER_SIZE];
    int			bufferLength;
    mad_synth	synth;
    mad_stream	stream;
    mad_frame	frame;
    int			bitRate;

public:
    FLACSoundData  ( Data * theData );
    FLACSoundData  ( const char * theFileName );
    ~FLACSoundData();

    virtual	int	getSize () const;

                                            // fill buffer with next audio data
    virtual	int	read ( byte * buf, int size = -1 );

                                            // position in sound (in seconds)
    virtual	bool	seek ( double time );

protected:
    int	readFrame ();
};

#endif

